/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-07-29 12:03:57
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-07-29 12:05:53
 * @FilePath: /vue3-uniapp/src/other/componentsResolvers/uniUiResolver.ts
 */

import type {
    ComponentResolver,
    SideEffectsInfo
} from 'unplugin-vue-components';

const camelToKebab = (str: string) => {
    return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
};

export const uniUiResolver = (): ComponentResolver[] => {
    return [
        {
            type: 'component',
            resolve: (name: string) => {
                if (!/^Uni[A-Z]\w*$/i.test(name)) {
                    return;
                }
                const componentName = camelToKebab(name.replace(/^Uni/, ''));
                // if (componentName === 'color-select') {
                //     return {
                //         name: 'default',
                //         from: 'tnuiv3p-tn-color-select/index.vue'
                //     };
                // }
                // if (componentName.indexOf('item') !== -1) {
                //     const matchName = componentName.match(/(.*)-item$/)![1];
                //     return {
                //         name: 'default',
                //         from: `@tuniao/tnui-vue3-uniapp/components/${matchName}/src/${componentName}.vue`
                //     };
                // }
                return {
                    name: 'default',
                    from: `@dcloudio/uni-ui/lib/uni-${componentName}/uni-${componentName}.vue` // uniapp通过后缀添加
                };
            }
        }
    ];
};
